package com.example.ui;


import com.example.model.Order;
import com.example.service.MsgService;
import com.example.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

@RestController
@RequestMapping(path = "/order")
public class OrderController {
    @Autowired
    MsgService msgService;

    @Autowired
    OrderService orderService;
    private final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);

    @PostMapping("/comfirmOrder.do")
    public void products() {
        Random random = new Random();
        Long goodsId = 112L;
        Long couponId = 113L;
        String userId = "15299843";
        Order order = new Order();

        order.setOrderId(Long.valueOf(random.nextInt(102515)));
        order.setGoodsId(112l);
        order.setUserId(userId);
        order.setGoodsNumber(1);
        order.setOrderAddress("北京");
        order.setGoodsPrice(new BigDecimal(10.0));
        order.setOrderAmount(new BigDecimal(100));
        order.setMoneyPaid(new BigDecimal(100));
        order.setCouponId(couponId);
        order.setGoodsAmount(new BigDecimal(1001));
        order.setShippingFee(new BigDecimal(0));
        order.setOrderConsignee("收货人");
        order.setCreateTime(new Date());

        orderService.commitOrder(order);
        msgService.orderMsgSend(order.getGoodsNumber(), "orderMsg");
        msgService.userMsgSend(order, "userMsg");
    }
}
